# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=ftgl

pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
_pkgver=2.1.3-rc5
pkgver=${_pkgver/-/}
pkgrel=1
pkgdesc="OpenGL library to use arbitrary fonts (mingw-w64)"
arch=('any')
url="http://ftgl.wiki.sourceforge.net/"
license=("MIT")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc" "${MINGW_PACKAGE_PREFIX}-pkg-config")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs" "${MINGW_PACKAGE_PREFIX}-freetype")
options=('staticlibs' 'strip')
source=("http://downloads.sourceforge.net/${_realname}/${_realname}-$_pkgver.tar.bz2"
    m4.gl.m4.patch)
md5sums=('c7879018cde844059495b3029b0b6503'
         '8590beb2dea7e28e7b7214ed562b2472')

prepare () {
  cd "${srcdir}/${_realname}-${_pkgver/-/~}"
  sed -i "s|SUBDIRS = src test demo docs|SUBDIRS = src|g" Makefile.am
  patch -p0 -i "${srcdir}"/m4.gl.m4.patch
  autoreconf -vfi
}

build() {
  rm -rf "${srcdir}/build-${MINGW_CHOST}"
  mkdir "${srcdir}/build-${MINGW_CHOST}"
  cd "${srcdir}/build-${MINGW_CHOST}"
  ../"${_realname}-${_pkgver/-/~}"/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --enable-static \
    --enable-shared \
    --without-x
  make ECHO=echo
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make ECHO=echo DESTDIR="$pkgdir" install

  # FS#23283: install missing headers for OpenCascade
  install -m644 $srcdir/"${_realname}-${_pkgver/-/~}"/src/FT{Face,Library,Size}.h "${pkgdir}${MINGW_PREFIX}/include/FTGL/"

  install -Dm644 $srcdir/"${_realname}-${_pkgver/-/~}"/COPYING "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
